﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;

namespace Bluebunnie
{
    /// <summary>
    /// Interaction logic for SearchBar.xaml
    /// </summary>
    public partial class SearchBar : UserControl
    {
        Selector _binding;

        string msg = "Masukkan kata kunci...";

        public SearchBar()
        {
            InitializeComponent();
            txtSearch.Text = msg;
        }

        public void BindList(Selector ms)
        {
            _binding = ms;
        }

        private void txtSearch_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (txtSearch.Text == msg) return;

            if (_binding != null)
                _binding.Items.Filter = o => o.ToString().Contains(txtSearch.Text);
        }

        private void txtSearch_GotFocus(object sender, RoutedEventArgs e)
        {
            if (txtSearch.Text == msg)
            {
                txtSearch.Text = string.Empty;
                txtSearch.FontStyle = FontStyles.Normal;
            }
        }

        private void txtSearch_LostFocus(object sender, RoutedEventArgs e)
        {
            if (txtSearch.Text.Length == 0)
            {
                txtSearch.FontStyle = FontStyles.Italic;
                txtSearch.Text = msg;
            }
        }
    }
}
